package com.aacar.controller.common;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.aacar.dto.CarSeriesTypeDto;
import com.aacar.dto.Header;
import com.aacar.service.CarSeriesService;
import com.aacar.utils.ResultInfoUtil;
import com.aacar.vo.CarSeriesTypeVo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;

/**
 * 车管理
 * @author wangh
 *
 */
@RestController
@RequestMapping("/carSeries")
public class CarController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private CarSeriesService carSeriesService;//车系别
	
	//获取所有车系类别
	@RequestMapping(value = "/getSeriesType/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getSeriesType(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody CarSeriesTypeDto cstd) {
		logger.info("request:/carSeries/getSeriesType/0" + JSONObject.toJSONString(cstd));
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<CarSeriesTypeVo> cstv = this.carSeriesService.getCarSeriesType(cstd);
		return ResultInfoUtil.setSuccessInfo(cstv,header.getService());
	}
	
	//获取所有车系列表
	@RequestMapping(value = "/getSeriesList/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getSeriesList(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody CarSeriesTypeDto cstd) {
		logger.info("request:/carSeries/getSeriesList/0" + JSONObject.toJSONString(cstd));
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<CarSeriesTypeVo> cstv = this.carSeriesService.getCarSeriesType(cstd);
		Map<String,Object> resultMap = Maps.newConcurrentMap();
		resultMap.put("info", cstv);
		return ResultInfoUtil.setSuccessInfo(resultMap,header.getService());
	}
	
	
	@RequestMapping(value = "/getSeriesByName/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getSeriesByName(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody CarSeriesTypeDto cstd) {
		logger.info("request:/carSeries/getSeriesByName/0" + JSONObject.toJSONString(cstd));
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<CarSeriesTypeVo> cstv = this.carSeriesService.getSeriesByName(cstd);
		Map<String,Object> resultMap = Maps.newConcurrentMap();
		resultMap.put("info", cstv);
		return ResultInfoUtil.setSuccessInfo(resultMap,header.getService());
	}
}
